package com.zzl.bonds.ticket.dto.finance;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.zzl.apidoc.annotation.ApidocModel;
import com.zzl.apidoc.annotation.ApidocModelProperty;
import com.zzl.apidoc.constants.RequiredType;
import com.zzl.bonds.ticket.dto.TicketDataDto;
import com.zzl.bonds.ticket.dto.TicketFinanceDataTypeDto;
import com.zzl.bonds.ticket.untils.DateUtils;
import com.zzl.general.common.utils.DoubleSerialize;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 融资申请单
 *
 * @author wztsl
 * @date 2022-02-24 13:53:42
 */
@Data
@ApidocModel
public class TicketFinanceAddDto implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 凭证基本信息
     */
    @NotBlank(message = "融资凭证id不能为空")
    @ApidocModelProperty(description = "融资凭证id", required = RequiredType.TRUE, example = "b0fbd5c0d42e4035a19e267e8ee09784")
    private String ticketId;
    @NotBlank(message = "凭证编号不能为空")
    @ApidocModelProperty(description = "凭证编号", required = RequiredType.TRUE, example = "EC220718151306002A")
    private String ticketNo;
    @NotNull(message = "凭证金额不能为空")
    @ApidocModelProperty(description = "凭证金额", required = RequiredType.TRUE, example = "10")
    private Double ticketAmount;

    @NotNull(message = "到期日期不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApidocModelProperty(description = "到期日期", validate = "yyyy-MM-dd", required = RequiredType.TRUE, example = "2022-09-09")
    private Date expireTime;
    @ApidocModelProperty(description = "付息方式 ：1 融资方付息（默认）2 核心企业付息")
    private Integer paymentMode;
    @NotNull(message = "开单企业id不能为空")
    @ApidocModelProperty(description = "开单企业id", required = RequiredType.TRUE, example = "1")
    private String coreEnterpriseId;
    @NotBlank(message = "开单企业名称不能为空")
    @ApidocModelProperty(description = "开单企业名称", required = RequiredType.TRUE, example = "天合集团")
    private String coreEnterpriseName;
    @ApidocModelProperty(description = "转单企业id", required = RequiredType.TRUE, example = "65")
    private String transferEnterpriseId;
    @ApidocModelProperty(description = "转单企业名称", required = RequiredType.TRUE, example = "南部路桥建设有限公司")
    private String transferEnterpriseName;
    @ApidocModelProperty(description = "备注", required = RequiredType.TRUE, example = "备注")
    private String remark;
    /**
     * 融资信息
     */
    @NotNull(message = "凭证的金融机构id不能为空")
    @ApidocModelProperty(description = "凭证的金融机构id", required = RequiredType.TRUE, example = "1")
    private String ticketInstinctyId;
    @NotBlank(message = "凭证的金融机构名称不能为空")
    @ApidocModelProperty(description = "凭证的金融机构名称", required = RequiredType.TRUE, example = "金融机构11")
    private String ticketInstinctyName;
    @NotNull(message = "转让金额不能为空")
    @ApidocModelProperty(description = "转让金额", required = RequiredType.TRUE, example = "1")
    private Double financeAmount;
    @NotBlank(message = "融资额度id不能为空")
    @ApidocModelProperty(description = "融资额度id", required = RequiredType.TRUE, example = "db8b01ac1cd04706a66c71af427cf2dc")
    private String supplierCreditId;
    @NotBlank(message = "额度编号不能为空")
    @ApidocModelProperty(description = "额度编号", example = "80bd89fc0ba3435e9cf73ab43446b931")
    private String creditNo;
    //    @NotBlank(message = "开单凭证的原始票id不能为空")
    @ApidocModelProperty(description = "开单凭证的原始票id")
    private String ticketOriginId;

    @NotNull(message = "入账银行账号id不能为空")
    @ApidocModelProperty(description = "入账银行账号id", required = RequiredType.TRUE, example = "2f32ccaee46f401c87ba25585ee9ef70")
    private String financeBankId;
    @NotBlank(message = "入账银行账号不能为空")
    @ApidocModelProperty(description = "入账银行账号", example = "444")
    private String financeDepositBank;
    @ApidocModelProperty(description = "开户行全称")
    private String fullNameOpeningBank;
    @NotBlank(message = "开户行全称不能为空")
    @ApidocModelProperty(description = "开户网点名称", required = RequiredType.TRUE, example = "北京银行")
    private String accountOpeningOutlet;

    @ApidocModelProperty(description = "合同编号")
    private String contractNo;

    @NotEmpty(message = "贸易合同文件不能为空")
    @ApidocModelProperty(description = "贸易合同文件")
    private List<TicketDataDto> proofList = new ArrayList<>();
    @NotEmpty(message = "发票信息不能为空")
    @ApidocModelProperty(description = "融资发票信息")
    private List<TicketDataDto> invoiceList = new ArrayList<>();
    @ApidocModelProperty(description = "融资资料信息")
    private List<TicketFinanceDataTypeDto> financeDataDtoList = new ArrayList<>();
    @NotNull(message = "金融机构id不能为空")
    @ApidocModelProperty(description = "金融机构id", required = RequiredType.TRUE, example = "1")
    private String instinctyId;
    @NotBlank(message = "金融机构名称不能为空")
    @ApidocModelProperty(description = "金融机构名称", required = RequiredType.TRUE, example = "兴业银行")
    private String instinctyName;
    @NotNull(message = "金融产品id不能为空")
    @ApidocModelProperty(description = "金融产品id", required = RequiredType.TRUE, example = "1")
    private String productId;
    @NotBlank(message = "金融产品名称不能为空")
    @ApidocModelProperty(description = "金融产品名称", required = RequiredType.TRUE, example = "测试产品")
    private String productName;

    @JsonSerialize(using = DoubleSerialize.class)
    @ApidocModelProperty(description = "平台服务费用", required = RequiredType.TRUE, example = "10")
    private Double serviceChage;
    @ApidocModelProperty(description = "平台服务费率", required = RequiredType.TRUE, example = "0.1")
    private Double platServiceRate;
    @ApidocModelProperty(description = "预计到账", required = RequiredType.TRUE, example = "1000")
    private Double estimateLoanAmount;
    @ApidocModelProperty(description = "融资成本", required = RequiredType.TRUE, example = "25")
    private Double financingCost;
    @ApidocModelProperty(description = "融资利率", required = RequiredType.TRUE, example = "0.15")
    private Double annualizedInterestRate;
    @ApidocModelProperty(description = "融资利息", required = RequiredType.TRUE, example = "15")
    private Double annualizedInterest;
    //    @JsonFormat(pattern = "yyyy-MM-dd")
//    @ApidocModelProperty(description = "预计放款日期", validate = "yyyy-MM-dd", required = RequiredType.TRUE, example = "2022-8-15")
    private Date estimateDisbursementDate;
    @ApidocModelProperty(description = "预计放款天数", required = RequiredType.TRUE, example = "3")
    private Integer estimateDisbursementDay;
    public Date getEstimateDisbursementDate() {
        if (null != estimateDisbursementDay) {
            estimateDisbursementDate = DateUtils.addDays(new Date(), estimateDisbursementDay);
        }
        return null;
    }
}
